const app = getApp()
const db = wx.cloud.database()
Page({
  data: {
    crmLIndex:0,
    show:true

  },
  // tab
  crmLIndex:function(e){
    console.log(e.currentTarget.dataset.index)
    let that = this
    that.setData({
      crmLIndex: e.currentTarget.dataset.index
    })
  },
  show:function(){
    let that = this
    that.setData({
      show:!that.data.show
    })
  },
  // 删除当前
  deleteShopUp:function(e){
    console.log(e.currentTarget.dataset.id)
    db.collection('shopUp').doc(e.currentTarget.dataset.id).remove({
        success: res => {
          wx.showToast({
            title: '删除成功',
          })
          wx.redirectTo({
            url: '/crm/pages/crm/crm?crmLIndex=3',
          })
        },
        fail: err => {
          wx.showToast({
            icon: 'none',
            title: '删除失败',
          })
          console.error('[数据库] [删除记录] 失败：', err)
        }
      })
  },

  tobanner:function(e){
    wx.navigateTo({
      url: '/crm/pages/banner/banner',
    })
  },
  tonav: function (e) {
    wx.navigateTo({
      url: '/crm/pages/nav/nav',
    })
  },
  toshop:function(e){
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '/crm/pages/shop/shop?id=' + e.currentTarget.dataset.id,
    })
  },
  backIndex:function(){
    wx.navigateTo({
      url: '/pages/home/world/world',
    })
  },
  totype:function(){
    wx.navigateTo({
      url: '/crm/pages/type/type',
    })
  },

  onLoad: function (options) {
    console.log(wx.getSystemInfoSync())
    let that = this
    that.setData({
      winh: wx.getSystemInfoSync().windowHeight,
      crmLIndex: options.crmLIndex
    })
    db.collection('shopUp').where({}).get({
      success: res => {
        console.log('[数据库] [查询记录] 成功: ', res)
        that.setData({
          shopUp: res.data
        })
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: '查询记录失败'
        })
        console.error('[数据库] [查询记录] 失败：', err)
      }
    })
    db.collection('shopType').where({}).get({
      success: res => {
        console.log('[数据库] [查询记录] 成功: ', res)
        that.setData({
          shopType: res.data
        })
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: '查询记录失败'
        })
        console.error('[数据库] [查询记录] 失败：', err)
      }
    })
    db.collection('banner').where({}).get({
      success: res => {
        console.log('[数据库] [查询记录] 成功: ', res)
        that.setData({
          banner: res.data
        })
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: '查询记录失败'
        })
        console.error('[数据库] [查询记录] 失败：', err)
      }
    })
  },

  onReady: function () {
    wx.getLocation({
      type: 'wsg84',
      altitude: true,
      success: function(res) {
        let jd = res.经度
        let wd = res.纬度
        wx.request({
          url: '你的url地址',
          data: {
            address:[jd,wd]
          },
          header: {},
          method: 'GET',
          dataType: 'json',
          responseType: 'text',
          success: function(res) {

          },
        })

      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  onShow: function () {
    
  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  }
})